package com.yunxi.controller.finance;

import com.github.pagehelper.PageInfo;
import com.yunxi.core.web.ApiResult;
import com.yunxi.core.web.CurrentUser;
import com.yunxi.core.web.LoginInfo;
import com.yunxi.core.web.ResponseUtil;
import com.yunxi.finance.pojo.VehiclePriceQueryReqVO;
import com.yunxi.finance.pojo.VehiclePriceQueryRespVO;
import com.yunxi.finance.pojo.VehiclePriceVO;
import com.yunxi.finance.service.VehiclePriceDubboService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 车辆价格 前端控制器
 * </p>
 *
 * @author
 * @since 2019-05-22
 */
@RestController
@RequestMapping("/admin/finance/vehiclePrice")
@Api(tags = "finance:vehiclePrice", description = "车辆价格接口")
public class VehiclePriceController {
    private static final Logger logger = LoggerFactory.getLogger(VehiclePriceController.class);

    @Autowired
    VehiclePriceDubboService vehiclePriceDubboService;


    @GetMapping("/queryVehiclePriceResult")
    @ApiOperation(value = "整车价格查询")
    public ApiResult queryVehiclePriceResult(VehiclePriceQueryReqVO vo, Integer pageNum, Integer pageSize){
         return ResponseUtil.ok(vehiclePriceDubboService.queryVehiclePriceResult(vo,pageNum,pageSize));
    }

    @GetMapping("/page")
    @ApiOperation(value = "查询分页")
    public ApiResult page(VehiclePriceVO vehiclePriceVO, Integer pageNum, Integer pageSize) throws Exception {
        return ResponseUtil.ok(vehiclePriceDubboService.findPageByVO(vehiclePriceVO, pageNum, pageSize));
    }

    @GetMapping("/load")
    @ApiOperation(value = "读取单个")
    public ApiResult<VehiclePriceVO> load(String id, @CurrentUser LoginInfo loginInfo) throws Exception {
        return ResponseUtil.ok(vehiclePriceDubboService.getById(id));
    }

    @PostMapping("/save")
    @ApiOperation(value = "保存信息")
    public ApiResult save(@RequestBody VehiclePriceVO vehiclePriceVO, @CurrentUser LoginInfo loginInfo) throws Exception {
        vehiclePriceVO.setCreateBy(loginInfo.getUserId());
        vehiclePriceDubboService.saveOrUpdate(vehiclePriceVO);
        return ResponseUtil.ok("success");
    }

    @GetMapping("/compoutePriceByCondition")
    @ApiOperation(value = "计算整车及选装包价格")
    public ApiResult compoutePriceByCondition(VehiclePriceQueryReqVO vo){
        return ResponseUtil.ok(vehiclePriceDubboService.compoutePriceByCondition(vo));
    }

    @PostMapping("/check")
    @ApiOperation(value = "保存信息")
    public ApiResult check(@RequestBody VehiclePriceVO vehiclePriceVO, @CurrentUser LoginInfo loginInfo) throws Exception {
        vehiclePriceDubboService.check(vehiclePriceVO);
        return ResponseUtil.ok("success");
    }

    @PostMapping("/checkBatch")
    @ApiOperation(value = "保存信息")
    public ApiResult check(@RequestBody List<VehiclePriceVO> vehiclePriceVOList, @CurrentUser LoginInfo loginInfo) throws Exception {
        vehiclePriceDubboService.check(vehiclePriceVOList);
        return ResponseUtil.ok("success");
    }

    @PostMapping("/del")
    @ApiOperation(value = "删除")
    public ApiResult del(@RequestBody List<VehiclePriceVO> baseVehiclePriceVOList) throws Exception {
        vehiclePriceDubboService.removeByListVo(baseVehiclePriceVOList);
        return ResponseUtil.ok("success");
    }
/*@PostMapping("/export")
@ApiOperation(value = "导出excel")
public Object export(@RequestParam Map<String,Object> params) throws Exception {
return ResponseUtil.ok(baseVehiclePriceDubboService.findMapByList(params));
}*/
}
